home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / CModalProgress 1.1 / CModalProgress.h < prev    next >
Text File  |  1995-02-18  |  5KB  |  145 lines

  1. // ===========================================================================
  2. //    ModalProgress.h
  3. //    
  4. //    This file contains the header information for the ModalProgress class.
  5. //    This class provides an interface for displaying to the user, a visual 
  6. //    indication to the progress of a time intensive task. 
  7. //
  8. //    The resource ID of a dialog resource is passed to the constructor which
  9. //    will be used in the progress dialog. There are a number of things to
  10. //    consider when creating the dialog as certain items must be present for
  11. //    some actions to take place.
  12. //
  13. //    If an OK equivalent button is needed, then use item 1 for this purpose.
  14. //    If you wish this button to have a border, create a user item the size of
  15. //    the outline, place it over the OK button, this should be item 3.
  16. //
  17. //    A CANCEL button should use item number 2, if required.
  18. //
  19. //    Standard key equvalents are supported, Enter, Return, Command-., ESC for
  20. //    each of these buttons.
  21. //
  22. //    If these particular items are not required by the dialog, they must be
  23. //    generated as hidden disabled items. Do not just leave the items out of
  24. //    the diaog.
  25. //
  26. //
  27. //    If a progress bar is required in the dialog (which is expected for most
  28. //    uses of this class) it should be generated as a user item that is the
  29. //    size of the frame that is required for this bar. The item number of this
  30. //    user item is passed to the SetProgressBar or SetInfiniteBar method.
  31. //    
  32. //    If a simple text value of percent complete is required, the item should
  33. //    be generated as a StaticText item, and its item number passed to the
  34. //    SetPercentText method along with the resolution of update.
  35. //
  36. //
  37. //    History
  38. //    -------
  39. //    
  40. //    Graham Heathcote, 1st of September 1994.
  41. //        -    Creation of initial version 1.0 release
  42. //
  43. //    Graham Heathcote, 5th of February 1995.
  44. //        -    Added two new fields to hold the UniversalProcPtrs needed for PowerPC compilers.
  45. //
  46. //    Graham Heathcote, 16th of February 1995.
  47. //        -    Added the SetParamText() method and the extra SetupDialog() method.
  48. //        -    Added the CanProcessEvent() method which lets the main application pass in an
  49. //            event for the dialog to process if it can.
  50. //        -    Added the ProcessIdle() method.
  51. //
  52. //    Version 1.1
  53. //
  54. //    Copyright 1994, 1995 Alysoft Solutions. All rights reserved.
  55. //
  56. // ===========================================================================
  57.  
  58. #ifndef __CMODALPROGRESS__
  59. #define __CMODALPROGRESS__
  60.  
  61. #ifndef __DIALOGS__
  62. #include <dialogs.h>
  63. #endif
  64.  
  65. typedef enum {
  66.     kDialogContinues                            = 0,
  67.     kDialogOKHit,
  68.     kDialogCancelHit,
  69.     kDialogExceeding100pc,
  70.  
  71.     kStateSpaceWithinLimit,
  72.     kStateSpaceExceedingLimit
  73. } tDialogProcessStates ;
  74.  
  75. typedef enum {
  76.     kDefaultButtonIndex                            = 1,
  77.     kCancelButtonIndex,
  78.     kDefaultButtonOutlineIndex
  79. } tDialogItemIndicies ;
  80.  
  81. #define    kIndicatorOutline                        0x0001
  82. #define    kIndicatorContent                        0x0002
  83.  
  84. #define    kDefaultInfiniteDrawDelay                1
  85. #define    kInfinitePaternResID                    6000
  86.  
  87. class CModalProgress
  88. {
  89.     private:
  90.         float                    fStartStatePercent ;
  91.         float                    fCurrentStateSpace ;
  92.         float                    fCurrentStateValue ;
  93.         float                    fCurrentStateSpacePercent ;
  94.         long                    fInfiniteDrawTime ;
  95.         Boolean                    fPercentText ;
  96.         Boolean                    fProgressBar ;
  97.         Boolean                    fInfiniteBar ;
  98.         short                    fPercentTextItem ;
  99.         short                    fProgressBarItem ;
  100.         short                    fInfiniteBarItem ;
  101.         short                    fPercentTextDeltaLimit ;
  102.         UserItemUPP                fButtonOutlineDrawProc ;
  103.         UserItemUPP                fProgressBarDrawProc ;
  104.  
  105.         Boolean            FlashButton(DialogPtr theDialog, short buttonIndex) ;
  106.         void            UpdateProgressIndicator(float newPercent) ;
  107.  
  108.     protected:
  109.         virtual Boolean    ProcessEvent(EventRecord *theEvent, short *result) ;
  110.         virtual    void    DrawPercentIndicator(float percent, short deltaLimit, short itemIndex, short part) ;
  111.         virtual    void    DrawStdBarIndicator(float percent, short itemIndex, short part) ;
  112.         virtual    void    DrawInfiniteBarIndicator(float percent, short itemIndex, short part) ;
  113.         virtual    short    CreateTheDialog(short dlgResId) ;
  114.  
  115.     public:
  116.         DialogPtr                fDialog ;
  117.         float                    fCurrentPercent ;
  118.         long                    fInfiniteDrawDelay ;
  119.  
  120.         CModalProgress() ;                            // Constructor
  121.         ~CModalProgress() ;                            // Destructor
  122.  
  123.         virtual void    SetParamText(void) ;
  124.         virtual    short    SetupDialog(short dlgResId) ;
  125.         virtual    short    SetupDialog(short dlgResId, ConstStr255Param param0, ConstStr255Param param1, ConstStr255Param param2, ConstStr255Param param3) ;
  126.         virtual    void    SetProgressBar(short dlgItem) ;
  127.         virtual    void    SetInfiniteBar(short dlgItem) ;
  128.         virtual    void    SetPercentText(short dlgItem, short deltaLimit) ;
  129.         
  130.         virtual    void    SetCurrentState(float statePercent) ;
  131.         virtual    void    SetStateSpace(float space) ;
  132.         virtual short    SetCurrentStateValue(float value) ;
  133.  
  134.         virtual    void    DrawProgressIndicator(float percent, short part) ;
  135.         
  136.         virtual    void    BeginModal(void) ;
  137.         virtual short    ProcessIdle(void) ;
  138.         virtual    short    ProcessModal(void) ;
  139.         virtual Boolean    CanProcessEvent(EventRecord *theEvent, short *result) ;
  140.         virtual    void    EndModal(void) ;
  141.  
  142. } ;
  143.  
  144. #endif
  145.